package com.baidu.automata.core.type;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import org.dom4j.Element;
import org.w3c.dom.Node;

import com.baidu.common.util.FieldUtil;

public class ListField extends DataField implements List<DataField> {
	private List<DataField> value = new ArrayList<DataField>();

	public ListField() {
		super();
	}

	public ListField(String id) {
		super(id);
	}

	@Override
	@SuppressWarnings("unchecked")
	public void deserialize(Element e) throws Exception {
		this.id = e.attributeValue("id");
		for (Iterator<Element> it = e.elementIterator(); it.hasNext();) {
			Element emt = it.next();
			this.value.add(FieldUtil.initFiled(emt));
		}
		
	}

	@Override
	public Node serialize() {
		return null;
	}

	@Override
	public int size() {
		return value.size();
	}

	@Override
	public boolean isEmpty() {
		return value.isEmpty();
	}

	@Override
	public boolean contains(Object o) {
		return this.value.contains(o);
	}

	@Override
	public Iterator<DataField> iterator() {
		return this.value.iterator();
	}

	@Override
	public Object[] toArray() {
		return this.value.toArray();
	}

	@Override
	public <T> T[] toArray(T[] a) {
		return this.value.toArray(a);
	}

	@Override
	public boolean remove(Object o) {
		return this.value.remove(o);
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		return this.value.containsAll(c);
	}

	@Override
	public boolean removeAll(Collection<?> c) {
		return this.value.removeAll(c);
	}

	@Override
	public boolean retainAll(Collection<?> c) {
		return this.value.retainAll(c);
	}

	@Override
	public void clear() {
		this.value.clear();
	}

	@Override
	public DataField get(int index) {
		return this.value.get(index);
	}

	@Override
	public DataField remove(int index) {
		return this.value.remove(index);
	}

	@Override
	public int indexOf(Object o) {
		return this.value.indexOf(o);
	}

	@Override
	public int lastIndexOf(Object o) {
		return this.value.lastIndexOf(o);
	}

	@Override
	public ListIterator<DataField> listIterator() {
		return this.value.listIterator();
	}

	@Override
	public ListIterator<DataField> listIterator(int index) {
		return this.value.listIterator(index);
	}

	@Override
	public List<DataField> subList(int fromIndex, int toIndex) {
		return this.value.subList(fromIndex, toIndex);
	}

	@Override
	public boolean add(DataField e) {
		return this.value.add(e);
	}

	@Override
	public boolean addAll(Collection<? extends DataField> c) {
		return this.addAll(c);
	}

	@Override
	public boolean addAll(int index, Collection<? extends DataField> c) {
		return this.value.addAll(index, c);
	}

	@Override
	public DataField set(int index, DataField element) {
		return this.set(index, element);
	}

	@Override
	public void add(int index, DataField element) {
		this.add(index, element);
	}
}
